import sys
from pylab import title, plot, show, legend, hold, gca, xlabel, ylabel, \
 savefig, errorbar, subplot, setp, xlim
   
def show_or_save(nm):
   if 'save' in sys.argv:
      savefig(nm)
   else:
      show()

if __name__=="__main__":
   from results import res
   d = {}
   for nm,miss,hit,tot,hitrate in res:
      x,y = d.get(nm, ([],[]))
      x.append(tot)
      y.append(hitrate)
      d[nm] = (x,y)
   #print d
   del d['PERFECTDatastore']
   title('Cache Hit-rate Comparison')
   xlabel('Number of Queries')
   ylabel('Hit-rate')
   for nm,data in d.items():
      x,y = data
      nm = nm.replace('Datastore','')
      plot(x, y, label=nm)
      #errorbar(x, y, yerr=e, fmt='-', label=nm)
   legend(loc='upper right')
   show_or_save('graph.png')
